package com.jcfk.eam.controller.mt;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.*;

import com.jcfk.eam.domain.dto.mt.EamMtUseApplyDTO;
import com.jcfk.eam.domain.dto.mt.EamMtUseApplyDetailDTO;
import com.jcfk.eam.domain.query.main.EamAssetInfoQuery;
import com.jcfk.eam.domain.query.mt.EamMtUseApplyQuery;
import com.jcfk.eam.service.mt.EamMtUseApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


import java.util.List;

/**
 * 量检具领用申请
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-09-08
 */
@Api(tags = {"量检具领用申请管理"})
@RestController
@RequestMapping("eammtuseapply")
public class EamMtUseApplyController {
    @Autowired
    private EamMtUseApplyService eamMtUseApplyService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamMtUseApplyQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询量检具领用申请")
    @PostMapping("/queryByPage")
    public RetPage<EamMtUseApplyDTO> queryByPage(@RequestBody ReqPageParam<EamMtUseApplyQuery> requestParam) {
        // 设置默认排序
        if (requestParam.getSort().getOrderItem() == null) {
            ReqSortParam<EamMtUseApplyQuery> sortParam = new ReqSortParam();
            sortParam.setColumn("lastUpdateTime");
            sortParam.setOrderBy("desc");
            requestParam.setSort(sortParam);
        }

        DataPage<EamMtUseApplyDTO> page = new DataPage<EamMtUseApplyDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                EamMtUseApplyDTO.class);
        page = eamMtUseApplyService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamMtUseApplyQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取量检具领用申请列表", notes = "获取量检具领用申请列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<EamMtUseApplyDetailDTO>> getDetails(@RequestBody EamMtUseApplyQuery query) {

        List<EamMtUseApplyDetailDTO> list = eamMtUseApplyService.getDetails(query);

        return RetResult.ok(list);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamMtUseApplyQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取量检具领用申请列表", notes = "获取量检具领用申请列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<EamMtUseApplyDTO>> getList(@RequestBody EamMtUseApplyQuery query) {

        List<EamMtUseApplyDTO> list = eamMtUseApplyService.getList(query);

        return RetResult.ok(list);
    }


    /**
     * 量检具领用申请
     * 根据id 查询详情
     */
    @ApiOperation("查询量检具领用申请")
    @GetMapping("/get/{id}")
    public RetResult<EamMtUseApplyDTO> get(@PathVariable("id") String id) {
        EamMtUseApplyDTO item = eamMtUseApplyService.get(id);
        return RetResult.ok(item);
    }
    /**
     * 量检具领用申请
     * 根据id 查询详情
     */
    @ApiOperation("查询量检具领用申请")
    @GetMapping("/code/get/{code}")
    public RetResult<EamMtUseApplyDTO> getbYcode(@PathVariable("code") String code) {
        EamMtUseApplyDTO item = eamMtUseApplyService.getBycode(code);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理量检具领用申请
     */
    @ApiOperation("保存量检具领用申请")
    @PostMapping("/save")
    @RequestLogHeader(modular = "量检具领用申请管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamMtUseApplyDTO eamMtUseApply) {
        // 数据校验
        RetResult ret = eamMtUseApplyService.isValid(eamMtUseApply);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamMtUseApply.getId())) {
            // 新增
            eamMtUseApplyService.insert(eamMtUseApply);
        } else {
            // 更新
            eamMtUseApplyService.update(eamMtUseApply);
        }
        return RetResult.ok();

    }


    /**
     * 批量删除量检具领用申请
     */
    @ApiOperation("批量删除量检具领用申请")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "量检具领用申请管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamMtUseApplyDTO eamMtUseApply) {
        return RetResult.ok(eamMtUseApplyService.removeBigBatch(eamMtUseApply.getIds()));
    }


    /**
     * 删除量检具领用申请
     */
    @ApiOperation("删除量检具领用申请")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "量检具领用申请管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamMtUseApplyService.deleteitem(id);
        return RetResult.ok();
    }
}
